package net.mysoft.budgetsoft.system.action;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import net.mysoft.budgetsoft.system.pagemodel.DictionaryDetail;
import net.mysoft.budgetsoft.system.pagemodel.FlowTaskNode;
import net.mysoft.budgetsoft.system.service.FlowTaskNodeService;
import net.mysoft.framework.base.BaseAction;
import net.mysoft.framework.model.DataGrid;
import net.mysoft.framework.model.Json;
import net.mysoft.framework.model.SessionInfo;
import net.mysoft.framework.util.ExceptionUtil;
import net.mysoft.framework.util.ResourceUtil;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ModelDriven;

/**
 * 
 * @author dagongPGP v1.0
 * @link <a href=http://www.dagongsoft.net>北京大公信软科技有限公司</a>
 * 
 * @version $Revision: 1.00 $Date: 2013-07-08 17:26:33
 */
@Action(value = "flowTaskNodeAction", results = { 
		@Result(name = "flowTaskNode", location = "/platform/system/flowTaskNode.jsp"), 
		@Result(name = "daiBanGZ", location = "/platform/layout/portal/daiBanGZ.jsp"), 
		@Result(name = "yiBanGZ", location = "/platform/layout/portal/yiBanGZ.jsp"), 
		@Result(name = "allDBWorkView", location = "/platform/system/allDBWorkView.jsp"), 
		@Result(name = "allYBWorkView", location = "/platform/system/allYBWorkView.jsp"), 
		@Result(name = "flowTaskNodeAdd", location = "/platform/system/flowTaskNodeAdd.jsp"), 
		@Result(name = "flowTaskNodeEdit", location = "/platform/system/flowTaskNodeEdit.jsp"), 
		@Result(name = "flowTaskNodeView", location = "/platform/system/flowTaskNodeView.jsp"), 
		@Result(name = "flowTaskNodeUser", location = "/platform/system/flowTaskNodeUser.jsp"), 
		@Result(name = "flowUserSelect", location = "/platform/system/flowUserSelect.jsp"), 
		@Result(name = "logView", location = "/platform/processLog.jsp") 
})
@Controller("flowTaskNodeAction")
public class FlowTaskNodeAction extends BaseAction implements ModelDriven<FlowTaskNode> {

	private static final Logger logger = Logger.getLogger(FlowTaskNodeAction.class);
	//@Resource
	private FlowTaskNodeService flowTaskNodeService;
	/*@Resource
	private XiangMuJBXXService xiangMuJBXXService;*/
	/*
	 * @Resource private RenWuJBXXService renWuJBXXService;
	 */

	private List<FlowTaskNode> ftnList = new ArrayList();

	public List<FlowTaskNode> getFtnList() {
		return ftnList;
	}

	public void setFtnList(List<FlowTaskNode> ftnList) {
		this.ftnList = ftnList;
	}

	private FlowTaskNode flowTaskNode = new FlowTaskNode();

	public FlowTaskNodeService getFlowTaskNodeService() {
		return this.flowTaskNodeService;
	}

	public void setFlowTaskNodeService(FlowTaskNodeService flowTaskNodeService) {
		this.flowTaskNodeService = flowTaskNodeService;
	}

	public FlowTaskNode getFlowTaskNode() {
		return this.flowTaskNode;
	}

	public void setFlowTaskNode(FlowTaskNode flowTaskNode) {
		this.flowTaskNode = flowTaskNode;
	}

	public void updateUser() {
		Json j = new Json();
		try {
			boolean b = flowTaskNodeService.updateUser(flowTaskNode.getFtn_ID(), flowTaskNode.getFtn_UserCode());
			j.setSuccess(true);
			j.setMsg("成功！");
		} catch (Exception e) {
			logger.error(ExceptionUtil.getExceptionMessage(e));
			e.printStackTrace();
			j.setMsg("失败！");
		}
		super.writeJson(j);

	}

	public FlowTaskNode getModel() {
		return flowTaskNode;
	}

	public String flowUserSelect() {
		return "flowUserSelect";
	}

	public String flowTaskNodeUser() {
		FlowTaskNode f = flowTaskNodeService.get(flowTaskNode.getFtn_ID());
		flowTaskNode.setFlowTemplateNodeID(f.getFlowTemplateNodeID());
		return "flowTaskNodeUser";
	}

	/**
	 * FlowTaskNode列表页面
	 * 
	 * @return
	 */
	public String flowTaskNode() {
		return "flowTaskNode";
	}

	/**
	 * FlowTaskNode查看页面
	 * 
	 * @return
	 */
	public String flowTaskNodeView() {
		return "flowTaskNodeView";
	}

	/**
	 * FlowTaskNode添加页面
	 * 
	 * @return
	 */
	public String flowTaskNodeAdd() {
		return "flowTaskNodeAdd";
	}

	/**
	 * FlowTaskNode编辑页面
	 * 
	 * @return
	 */
	public String flowTaskNodeEdit() {
		return "flowTaskNodeEdit";
	}

	/**
	 * FlowTaskNode编辑页面
	 * 
	 * @return
	 */
	public String processLog() {
		// flowTaskNode.setSort("ftn_HandleBeginTime,ftn_HandleEndTime");
		// flowTaskNode.setOrder("asc,asc");
		// ftnList = flowTaskNodeService.findAll(flowTaskNode);
		return "logView";
	}

	/**
	 * 首页-待办工作
	 * 
	 */
	public String daiBanGZ() {
		try {
			flowTaskNode.setSort("ftn_HandleBeginTime");
			flowTaskNode.setOrder("desc");
			flowTaskNode.setFtn_Status(1);
			flowTaskNode.setPage(1);
			flowTaskNode.setRows(4);
			SessionInfo sessionInfo = (SessionInfo) super.getSession().getAttribute(ResourceUtil.getSessionInfoName());
			flowTaskNode.setFtn_UserCode(sessionInfo.getUserId());
			/*flowTaskNode.setXiangMuZT(TXiangMuJBXX.CHUPING);*/
			ftnList = flowTaskNodeService.find(flowTaskNode);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return "daiBanGZ";
	}

	/**
	 * 查看更多待办工作页面
	 */
	public String allDBWorkView() {
		return "allDBWorkView";
	}

	/**
	 * 查看更多待办工作的列表
	 */
	public void workDBDatagrid() {
		try {
			SessionInfo sessionInfo = (SessionInfo) super.getSession().getAttribute(ResourceUtil.getSessionInfoName());
			flowTaskNode.setSort("ftn_HandleBeginTime");
			flowTaskNode.setOrder("desc");
			flowTaskNode.setFtn_Status(1);
			flowTaskNode.setFtn_UserCode(sessionInfo.getUserId());
			/*flowTaskNode.setXiangMuZT(TXiangMuJBXX.CHUPING);*/
			DataGrid dg = flowTaskNodeService.datagrid(flowTaskNode, null, null, null, null);
			
			// System.out.println("@@@@@@@@@@  "+dg.getRows().size());
			super.writeJson(dg);
		} catch (Exception e) {
			logger.error(ExceptionUtil.getExceptionMessage(e));
		}
	}

	/**
	 * 首页-已办工作
	 * 
	 */
	public String yiBanGZ() {
		try {
			flowTaskNode.setSort("ftn_HandleEndTime,ftn_HandleBeginTime");
			flowTaskNode.setOrder("desc,desc");
			flowTaskNode.setFtn_Status(2);
			flowTaskNode.setPage(1);
			flowTaskNode.setRows(4);
			/*flowTaskNode.setXiangMuZT(TXiangMuJBXX.CHUPING);*/
			SessionInfo sessionInfo = (SessionInfo) super.getSession().getAttribute(ResourceUtil.getSessionInfoName());
			flowTaskNode.setFtn_UserCode(sessionInfo.getUserId());
			ftnList = flowTaskNodeService.find(flowTaskNode);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "yiBanGZ";
	}

	/**
	 * 查看更多已办工作页面
	 */
	public String allYBWorkView() {
		return "allYBWorkView";
	}

	/**
	 * 查看更多已办工作的列表
	 */
	public void workYBDatagrid() {
		try {
			SessionInfo sessionInfo = (SessionInfo) super.getSession().getAttribute(ResourceUtil.getSessionInfoName());
			flowTaskNode.setSort("ftn_HandleEndTime,ftn_HandleBeginTime");
			flowTaskNode.setOrder("desc,desc");
			flowTaskNode.setFtn_Status(2);
			/*flowTaskNode.setXiangMuZT(TXiangMuJBXX.CHUPING);*/
			flowTaskNode.setFtn_UserCode(sessionInfo.getUserId());
			DataGrid dg = flowTaskNodeService.datagrid(flowTaskNode, null, null, null, null);
			
			super.writeJson(dg);
		} catch (Exception e) {
			logger.error(ExceptionUtil.getExceptionMessage(e));
		}
	}

	/**
	 * 列表
	 */
	public void find() {
		try {
			super.writeJson(flowTaskNodeService.find(flowTaskNode, null, null, null, null));
		} catch (Exception e) {
			logger.error(ExceptionUtil.getExceptionMessage(e));
		}
	}

	/**
	 * 列表
	 */
	public void datagrid_His() {
		try {
			super.writeJson(flowTaskNodeService.datagrid_His(flowTaskNode, null, null, null, null));
		} catch (Exception e) {
			logger.error(ExceptionUtil.getExceptionMessage(e));
		}
	}

	/**
	 * 列表
	 */
	public void datagrid() {
		try {
			super.writeJson(flowTaskNodeService.datagrid(flowTaskNode, null, null, null, null));
		} catch (Exception e) {
			logger.error(ExceptionUtil.getExceptionMessage(e));
		}
	}

	/**
	 * 根据阶段id获得流程节点的下拉列表数据
	 */
	public void liuChengJDSelectData() {
		try {
			List<DictionaryDetail> oList = flowTaskNodeService.liuChengJDSelectData(flowTaskNode);
			super.writeJson(oList);
		} catch (Exception e) {
			logger.error(ExceptionUtil.getExceptionMessage(e));
		}
	}

	/**
	 * 催办
	 */
	public void cuiBan() {
		Json j = new Json();
		try {
			flowTaskNodeService.cuiBan(flowTaskNode);
			j.setSuccess(true);
			j.setMsg("催办成功！");
		} catch (Exception e) {
			logger.error(ExceptionUtil.getExceptionMessage(e));
			e.printStackTrace();
			j.setMsg("催办失败！");
		}
		super.writeJson(j);
	}

	/**
	 * 判断前台的ftnid是否有效
	 */
	public void checkFtn() {
		Json j = new Json();
		try {
			j.setSuccess(true);
			j.setObj(flowTaskNodeService.checkFtn(flowTaskNode));
		} catch (Exception e) {
			logger.error(ExceptionUtil.getExceptionMessage(e));
			e.printStackTrace();
		}
		super.writeJson(j);
	}

	/**
	 * 修改项目异常类型
	 */
	public void editXiangMuYCLX() {
		Json j = new Json();
		try {
			flowTaskNodeService.editXiangMuYCLX(flowTaskNode);
			j.setSuccess(true);
			j.setMsg("修改成功！");
		} catch (Exception e) {
			logger.error(ExceptionUtil.getExceptionMessage(e));
			e.printStackTrace();
			j.setMsg("修改失败！");
		}
		super.writeJson(j);
	}

}
